package com.hourse.platform.vo;

import com.alibaba.fastjson.JSONObject;
import com.hourse.platform.common.ErrorMsg;
import com.hourse.platform.utils.BeanTools;
import lombok.Data;

import java.io.Serializable;

/**
 * @使用描述: PageData
 */
@Data
public class PageData implements Serializable {

  public static final Integer SUCCESS_CODE = 20000;

  public static final String SUCCESS_MSG = "操作成功...";

  private Integer code = 20000;

  private String msg = SUCCESS_MSG;

  private Object data;

  public static PageData New(){
    return new PageData();
  }

  public PageData SUCCESS(){

    this.code = SUCCESS_CODE;

    return this;
  }

  public PageData SUCCESS(Object data){

    this.code = SUCCESS_CODE;
    this.data = data;
    return this;
  }

  public PageData SUCCESS(Object data,String msg){

    this.code = SUCCESS_CODE;
    this.data = data;
    this.msg = msg;
    return this;
  }

  public static PageData ERROR(ErrorMsg errorMsg){
      PageData pageData = PageData.New();
      pageData.msg = errorMsg.msg();
      pageData.code = errorMsg.code();
    return pageData;
  }

  public static PageData ERROR(Integer code ,String errorMsg){
    PageData pageData = PageData.New();
    pageData.msg = errorMsg;
    pageData.code = code;
    return pageData;
  }

  public JSONObject toJson(){
    return BeanTools.ToJson(this);
  }

}
